package com.cleaningcloud.cld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.cld.domain.dto.CldRewardsDto;
import com.cleaningcloud.cld.domain.vo.CldRewardsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldRewards;
import com.cleaningcloud.cld.service.ICldRewardsService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 奖惩管理Controller
 * 
 * @author cleaningcloud
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/CldRewards")
public class CldRewardsController extends BaseController
{
    @Autowired
    private ICldRewardsService cldRewardsService;

    /**
     * 查询奖惩管理列表
     */
    @RequiresPermissions("cld:CldRewards:list")
    @GetMapping("/list")
    public TableDataInfo list(CldRewardsDto cldRewards)
    {
        startPage();
        List<CldRewardsVo> list = cldRewardsService.selectCldRewardsList(cldRewards);
        return getDataTable(list);
    }

    /**
     * 导出奖惩管理列表
     */
    @RequiresPermissions("cld:CldRewards:export")
    @Log(title = "奖惩管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldRewardsDto cldRewards)
    {
        List<CldRewardsVo> list = cldRewardsService.selectCldRewardsList(cldRewards);
        ExcelUtil<CldRewardsVo> util = new ExcelUtil<CldRewardsVo>(CldRewardsVo.class);
        util.exportExcel(response, list, "奖惩管理数据");
    }

    /**
     * 获取奖惩管理详细信息
     */
    @RequiresPermissions("cld:CldRewards:query")
    @GetMapping(value = "/{rewardsId}")
    public AjaxResult getInfo(@PathVariable("rewardsId") Long rewardsId)
    {
        return success(cldRewardsService.selectCldRewardsByRewardsId(rewardsId));
    }

    /**
     * 新增奖惩管理
     */
    @RequiresPermissions("cld:CldRewards:add")
    @Log(title = "奖惩管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldRewardsDto cldRewards)
    {
        return toAjax(cldRewardsService.insertCldRewards(cldRewards));
    }

    /**
     * 修改奖惩管理
     */
    @RequiresPermissions("cld:CldRewards:edit")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldRewards cldRewards)
    {
        return toAjax(cldRewardsService.updateCldRewards(cldRewards));
    }


    /**
     * 修改奖惩管理
     */
    @RequiresPermissions("cld:CldRewards:audit")
    @Log(title = "奖惩管理", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody CldRewards cldRewards)
    {
        return toAjax(cldRewardsService.auditCldRewards(cldRewards));
    }

    /**
     * 删除奖惩管理
     */
    @RequiresPermissions("cld:CldRewards:remove")
    @Log(title = "奖惩管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rewardsIds}")
    public AjaxResult remove(@PathVariable Long[] rewardsIds)
    {
        return toAjax(cldRewardsService.deleteCldRewardsByRewardsIds(rewardsIds));
    }
}
